

module.exports = () => {
  return async function functionjwtErr(ctx, next) {
    const token = ctx.request.header.authorization;
    if (token) {
      try {
        if (await ctx.helper.verifyJwtToken(token)) {
          await next();
        } else {
          ctx.status = 401;
          ctx.body = {
            message: '登录超时,请重新登录',
          };
        }
      } catch (error) {
        ctx.status = 500;
        ctx.body = {
          message: error.message,
        };
        return;
      }
    } else {
      ctx.status = 401;
      ctx.body = {
        message: '请先登录',
      };
      return;
    }
  };
};
